package com.welldone.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.welldone.po.User;
import com.welldone.service.LoginService;
/**
 *@Description
 *@author your name
 *@createDate 2011-5-25 下午10:22:10
 *@version V1.0
 */
public class LoginServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			String uName = request.getParameter("uName");
			String uPass = request.getParameter("uPass");
			LoginService ls  = new LoginService();
			User user = ls.userLogin(uName, uPass);
			if(null == user.getUserId()){
				request.setAttribute("error", "用户名或密码不正确");
				request.getRequestDispatcher("login.jsp").forward(request, response);
			} else{
			if("0".equals(user.getUserStatus())){
				response.sendRedirect("index.jsp");
			}else{
				request.setAttribute("error", "用户已在别处登录，无法再次登录");
				request.getRequestDispatcher("login.jsp").forward(request, response);
			}
			}
			
	}
	
	

	
}


